use std::collections::HashMap;
use std::sync::Arc;

use reqwest::blocking;
use serde::Deserialize;
use threadpool::ThreadPool;

#[derive(Debug, Deserialize)]
struct Res {
    code: u16,
    message: String,
    // #[serde(skip_serializing)]
    // data: Option<String>,
}

fn main1() {
    let pool = ThreadPool::new(100);
    let client = Arc::new(blocking::Client::new());
    let url = "http://localhost:3000/register";
    let key1 = "nickname";
    let key2 = "password";
    for i in 0..100000000 {
        let copy = Arc::clone(&client);
        pool.execute(move || {
            let mut param = HashMap::new();
            let mut a = String::from("0000admin");
            a.push_str(&*i.to_string());
            param.insert(key1, a.clone());
            param.insert(key2, a);
            let serialized = serde_json::to_string(&param).unwrap();
            let res = copy
                .post(url)
                .header("Content-Type", "application/json")
                .body(serialized)
                .send();
            match res {
                Ok(r) => {
                    match r.text() {
                        Ok(t) => println!("{t}"),
                        Err(e) => println!("{:?}", e),
                    }
                }
                Err(e) => println!("{:?}", e),
            }
        });
    }
    pool.join();
    println!("程序运行结束");
}
